package com.example.service;

import com.example.demo2.EventManager;
import com.example.demo2.MQEventListener;
import com.example.demo2.MessageEventListener;
import com.example.entity.UserInfo;

public abstract class LotteryService {

    private EventManager eventManager;

    public LotteryService() {
        this.eventManager = new EventManager(EventManager.EventType.MQ, EventManager.EventType.MESSAGE);
        this.eventManager.subscribe(EventManager.EventType.MESSAGE, new MessageEventListener());
        this.eventManager.subscribe(EventManager.EventType.MQ, new MQEventListener());
    }

    /**
     * 摇号的逻辑
     *
     * @param uid
     */
    public abstract UserInfo lottery(String uid);


    /**
     * 发送消息的逻辑
     *
     * @param uid
     */
    public UserInfo notify(String uid) {
        UserInfo lottery = lottery(uid);
        //发送通知
        eventManager.notify(lottery);
        return lottery;
    }
}
